<?php include("includes/session.php"); ?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?php echo $lang['PAGE_TITLE_EDIT_LINKS']; ?></title>
<?php include("header.php"); ?>
<br />
<?php
if(!$session->logged_in)
{
?>
<center>
<table cellpadding="0" cellspacing="0" width="70%">
<tr>
	<td class="topLeft"></td><td bgcolor="#dadada"></td><td class="topRight"></td>
</tr>
<tr bgcolor="#dadada">
<td></td><td>
	<center><h3><?php echo $lang['PROFILE_EDIT_LINKS_LOGIN']; ?></h3></center>
	<center>Please <a href="index.php"><?php echo $lang['PROFILE_EDIT_LINKS_NOT_LOGGED']; ?></center>
</td><td></td>
</tr>
<tr>
	<td class="bottomLeft"></td><td bgcolor="#dadada"></td><td class="bottomRight"></td>
</tr>
</table>
</center>
<?php
}
else
{
?>
	<center>
	<table cellpadding="0" cellspacing="0" width="70%">
	<tr>
		<td class="topLeft"></td><td bgcolor="#dadada"></td><td class="topRight"></td>
	</tr>
	<tr bgcolor="#dadada">
	<td></td><td>
	<?php
	if(isset($_SESSION['linksuccess']))
	{
		if($_SESSION['linksuccess'])
		{
			echo "<center><h3>Link Successfully Added</h3></center>";
			echo "<center><a href=\"editLinks.php\">Add Link</a></center>";
		}
		else
		{
			echo "<center><h3>Link Failed to be Added</h3></center>";
			echo "<center>Please Try Again Later.</center>";
		}
		unset($_SESSION['linksuccess']);
	}
	else if(isset($_SESSION['linkeditsuccess']))
	{
		if($_SESSION['linkeditsuccess'])
		{
			echo "<center><h3>Link Successfully Edited</h3></center>";
			echo "<center><a href=\"editLinks.php\">Add Link</a></center>";
		}
		else
		{
			echo "<center><h3>Link Failed to be Edited</h3></center>";
			echo "<center>Please Try Again Later.</center>";
		}
		unset($_SESSION['linkeditsuccess']);
	}
	else if(isset($_GET['edit']))
	{
		$result = $database->query("SELECT * FROM ".TBL_LINKS." WHERE id='".$_GET['edit']."'");
		$link = mysql_fetch_array($result);
	?>
		<center><h2><?php echo $lang['PROFILE_EDIT_LINKS_EDIT']; ?></h2></center>
		<center>
		<form action="includes/process.php" method="post">
		<table cellpadding="3" cellspacing="0">
		<tr>
			<td><b><?php echo $lang['PROFILE_EDIT_LINKS_ADD_DISPLAY']; ?></b></td>
			<td><input type="text" size="40" name="link" value="<?php if($form->value("link")==""){ echo $link['link']; }else{ echo $form->value("link"); } ?>" /></td>
		</tr>
		<tr>
			<td></td>
			<td align="center"><font size="-2" color="#666666"><i><?php echo $lang['PROFILE_EDIT_LINKS_ADD_DISPLAY_EX']; ?></i></font></td>
		</tr>
		<tr>
			<td><b><?php echo $lang['PROFILE_EDIT_LINKS_ADD_URL']; ?></b></td>
			<td><input type="text" size="40" name="url" value="<?php if($form->value("url")==""){ echo $link['url']; }else{ echo $form->value("url"); } ?>" /></td>
		</tr>
		<tr>
			<td></td>
			<td align="center"><font size="-2" color="#666666"><i><?php echo $lang['PROFILE_EDIT_LINKS_ADD_URL_EX']; ?></i></font></td>
		</tr>
		<tr>
			<td valign="top"><b><?php echo $lang['PROFILE_EDIT_LINKS_ADD_DESC']; ?></b></td>
			<td><textarea name="description" cols="30" rows="5"><?php if($form->value("description")==""){ echo $link['description']; }else{ echo $form->value("description"); } ?></textarea></td>
		</tr>
		<tr>
			<td><input type="hidden" name="subEditLink" value="<?php echo $_GET['edit']; ?>" /></td>
			<td align="right"><input type="submit" value="Edit Link" /></td>
		</tr>
		</table>
		</form>
		</center>
	<?php
	}
	else
	{
	?>
		<center><h2><?php echo $lang['PROFILE_EDIT_LINKS_ADD_LINK']; ?></h2></center>
		<center>
		<form action="includes/process.php" method="post">
		<table cellpadding="3" cellspacing="0">
		<tr>
			<td><b><?php echo $lang['PROFILE_EDIT_LINKS_ADD_DISPLAY']; ?></b></td>
			<td><input type="text" size="40" name="link" value="<?php echo $form->value("link"); ?>" /></td>
		</tr>
		<tr>
			<td></td>
			<td align="center"><font size="-2" color="#666666"><i><?php echo $lang['PROFILE_EDIT_LINKS_ADD_DISPLAY_EX']; ?></i></font></td>
		</tr>
		<tr>
			<td><b><?php echo $lang['PROFILE_EDIT_LINKS_ADD_URL']; ?></b></td>
			<td><input type="text" size="40" name="url" value="<?php echo $form->value("url"); ?>" /></td>
		</tr>
		<tr>
			<td></td>
			<td align="center"><font size="-2" color="#666666"><i><?php echo $lang['PROFILE_EDIT_LINKS_ADD_URL_EX']; ?></i></font></td>
		</tr>
		<tr>
			<td valign="top"><b><?php echo $lang['PROFILE_EDIT_LINKS_ADD_DESC']; ?></b></td>
			<td><textarea name="description" cols="30" rows="5"><?php echo $form->value("description"); ?></textarea></td>
		</tr>
		<tr>
			<td>
			<input type="hidden" name="subAddLink" value="1" />
			<input type="hidden" name="creator" value="<?php echo $session->username; ?>" />
			</td>
			<td align="right"><input type="submit" value="<?php echo $lang['PROFILE_EDIT_LINKS_EDIT_ADD_BUT']; ?>" /></td>
		</tr>
		</table>
		</form>
		</center>
	<?php
	}
	?>
	</td><td></td>
	</tr>
	<tr>
		<td class="bottomLeft"></td><td bgcolor="#dadada"></td><td class="bottomRight"></td>
	</tr>
	</table>
	</center>
<br />
<center>
<table cellpadding="0" cellspacing="0" width="95%">
<tr>
	<td class="topLeft"></td><td bgcolor="#dadada"></td><td class="topRight"></td>
</tr>
<tr bgcolor="#dadada">
<td></td><td>
	<?php displayOwnerLinks($session->username); ?>
</td><td></td>
</tr>
<tr>
	<td class="bottomLeft"></td><td bgcolor="#dadada"></td><td class="bottomRight"></td>
</tr>
</table>
</center>
<?php
}
include("footer.php"); ?>